﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.Windows.Documents;
using System.Windows.Media.TextFormatting;
using System.Windows;

namespace SmartPaginator.Elements
{
    /// <summary>
    /// Container visual that represents an Inline.
    /// </summary>
    public class InlineElement : UIElement
    {
        #region Constructor

        public InlineElement()
            : this(double.NaN, double.NaN)
        {
        }

        public InlineElement(double width, double height)
        {
            Width = width;
            Height = height;
            DrawingVisual = new DrawingVisual();
        }

        #endregion

        #region Properties

        public double Width { get; private set; }
        
        public double Height { get; private set; }
        
        protected DrawingVisual DrawingVisual { get; private set; }

        #endregion

        #region RenderOpen Method

        public DrawingContext RenderOpen()
        {
            return DrawingVisual.RenderOpen();
        }

        #endregion

        #region Overriden Methods

        protected override Size MeasureCore(Size availableSize)
        {
            return new Size(Width, Height);
        }

        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawDrawing(DrawingVisual.Drawing);
        }

        #endregion

        #region GetCopy Method

        public InlineElement GetCopy()
        {
            var copy = new InlineElement(this.Width, this.Height);
            using (var context = copy.RenderOpen())
            {
                context.DrawDrawing(this.DrawingVisual.Drawing);
            }
            return copy;
        }

        #endregion
    }
}
